//
//  FeedbackViewController.m
//  Lovetome
//
//  Created by Xiemaoxiong on 16/7/8.
//  Copyright © 2016年 上海爱途蜜网络科技有限公司. All rights reserved.
//

#import "FeedbackViewController.h"
#import "PlaceholderTextView.h"

@interface FeedbackViewController()<UITextViewDelegate>
@property (nonatomic, strong) PlaceholderTextView * phoneView;
@property (nonatomic, strong) PlaceholderTextView * textView;
@property (nonatomic, strong) XMXButton *sendButton;
@end

@implementation FeedbackViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.title = @"意见反馈";
    
    [self.view addSubview:self.phoneView];
    [self.view addSubview:self.textView];
    [self.view addSubview:self.sendButton];
    [self layoutSubviews];
    

    

    
}

#pragma mark - masonry
- (void)layoutSubviews {
    
    [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).offset(Padding(30));
        make.right.mas_equalTo(self.view.mas_right).offset(-Padding(30));
        make.top.mas_equalTo(self.mas_topLayoutGuideBottom).offset(Padding(30));
        make.height.mas_equalTo(Size(100));
    }];
    
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).offset(Padding(30));
        make.right.mas_equalTo(self.view.mas_right).offset(-Padding(30));
        make.top.mas_equalTo(self.phoneView.mas_bottom).offset(Padding(30));
        make.height.mas_equalTo(Size(380));
    }];
    
    [self.sendButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).offset(Padding(30));
        make.right.mas_equalTo(self.view.mas_right).offset(-Padding(30));
        make.height.mas_equalTo(Size(100));
        make.top.mas_equalTo(self.textView.mas_bottom).offset(Padding(30));
    }];
    
}


#pragma mark - get&set
-(PlaceholderTextView *)phoneView{
    
    if (!_phoneView) {
        _phoneView = [[PlaceholderTextView alloc] init];
        _phoneView.backgroundColor = Color_input_backGroundColor;
        _phoneView.delegate = self;
        _phoneView.font = FontSize(30);
        _phoneView.textColor = [UIColor blackColor];
        _phoneView.textAlignment = NSTextAlignmentLeft;
        _phoneView.editable = YES;
        _phoneView.layer.cornerRadius = 4.0f;
        _phoneView.layer.borderColor = Color_input_backGroundColor.CGColor;
        _phoneView.layer.borderWidth = 0.5;
        _phoneView.placeholderColor = color_text_threelevel;
        _phoneView.placeholder = @"联系方式QQ、邮箱、手机号";
    }
    
    return _phoneView;
}

-(PlaceholderTextView *)textView{
    
    if (!_textView) {
        _textView = [[PlaceholderTextView alloc] init];
        _textView.backgroundColor = Color_input_backGroundColor;
        _textView.delegate = self;
        _textView.font = [UIFont systemFontOfSize:14.f];
        _textView.textColor = [UIColor blackColor];
        _textView.textAlignment = NSTextAlignmentLeft;
        _textView.editable = YES;
        _textView.layer.cornerRadius = 4.0f;
        _textView.layer.borderColor = Color_input_backGroundColor.CGColor;
        _textView.layer.borderWidth = 0.5;
        _textView.placeholderColor = color_text_threelevel;
        _textView.placeholder = @"请写下你对爱途蜜的感受，我们将不断进取，为你做的更好!";
    }
    
    return _textView;
}

- (XMXButton *)sendButton {
    if (!_sendButton) {
        _sendButton = [[XMXButton alloc] initWithTitle:@"发送" StateNormalTitleColor:[UIColor whiteColor] StateHighlightedTitleColor:nil TitleFont:FontSize(30) BackGroundColor:Color_MainColor_Red cornerRadius:25 borderColor:nil borderWidth:0 contentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter block:^{
            DDLogInfo(@"提交发送");
        }];
    }
    return _sendButton;
}


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    
    if ([@"\n" isEqualToString:text] == YES)
    {
        [textView resignFirstResponder];

        return NO;
    }
    
    return YES;
}


@end
